package com.platform.modules.app.controller;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.google.common.collect.ImmutableMap;
import com.platform.annotation.IgnoreAuth;
import com.platform.annotation.LoginUser;
import com.platform.common.exception.BusinessException;
import com.platform.common.utils.*;
import com.platform.common.validator.AbstractAssert;
import com.platform.modules.bk.entity.BkCustomerEntity;
import com.platform.modules.bk.service.BkCustomerService;
import com.platform.modules.event.entity.EventCalendarCategoryEntity;
import com.platform.modules.event.entity.EventCalendarEntity;
import com.platform.modules.event.entity.EventUserEntity;
import com.platform.modules.event.service.EventCalendarCategoryService;
import com.platform.modules.event.service.EventCalendarService;
import com.platform.modules.event.service.EventUserService;
import com.platform.modules.mall.entity.*;
import com.platform.modules.mall.service.*;
import com.platform.modules.sms.util.SmsUtil;
import com.platform.modules.sys.dao.SysConfigDao;
import com.platform.modules.sys.entity.SysSmsLogEntity;
import com.platform.modules.sys.service.SysConfigService;
import com.platform.modules.sys.service.SysSmsLogService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @author
 */
@Slf4j
@RestController
@RequestMapping("/app/index")
@Api(tags = "AppIndexController|APP首页接口")
public class AppIndexController extends AppBaseController {
    @Autowired
    private MallBannerService bannerService;
    @Autowired
    private MallPopupService popupService;
    @Autowired
    private WxMaService wxMaService;
    @Autowired
    private MallChannelService channelService;
    @Autowired
    private MallBulletinService bulletinService;
    @Autowired
    private MallOrderService orderService;
    @Autowired
    private SysConfigService sysConfigService;
    @Autowired
    private SysSmsLogService sysSmsLogService;
    @Autowired
    private MallUserService userService;
    @Autowired
    private BkCustomerService bkCustomerService;
    @Autowired
    MallModuleCategoryService moduleCategoryService;
    @Autowired
    MallModuleService moduleService;
    @Autowired
    MallGoodsService mallGoodsService;

    @Autowired
    EventUserService eventUserService;

    @Autowired
    EventCalendarService eventCalendarService;


    @Autowired
    EventCalendarCategoryService eventCalendarCategoryService;

    @Autowired
    private JedisUtil jedisUtil;
    @Autowired
    private MallRuleService mallRuleService;
    @Value("${ali.codeTemplateId}")
    private String templateId;
    @Value("${qq.map.key}")
    private String key;


    /**
     * 获取字典配置
     */
    @IgnoreAuth
    @GetMapping("/getDist")
    @ApiOperation(value = "获取字典配置", notes = "获取字典配置")
    public RestResponse getDist(@RequestParam String key) {
        return RestResponse.success().put("data", ((SysConfigDao) sysConfigService.getBaseMapper()).queryByCode(key));
    }

    /**
     * 获取H5配置
     */
    @IgnoreAuth
    @GetMapping("/getConfig")
    @ApiOperation(value = "获取H5配置", notes = "获取H5配置")
    public RestResponse getRuleDetail(@RequestParam String key) {
        return RestResponse.success().put("data", sysConfigService.getValue("H5_" + key));
    }

    /**
     * 获取平台规则详情
     */
    @IgnoreAuth
    @GetMapping("/getRuleDetail")
    @ApiOperation(value = "平台规则详情", notes = "获取平台规则详情")
    public RestResponse getRuleDetail(@RequestParam(defaultValue = "1") Integer type) {
        MallRuleEntity ruleEntity = mallRuleService.getOne(
                new QueryWrapper<MallRuleEntity>().eq("TYPE", type), false);
        return RestResponse.success().put("data", ruleEntity);
    }

    /**
     * 首页轮播图列表
     */
    @IgnoreAuth
    @GetMapping("/bannerList")
    @ApiOperation(value = "首页轮播图列表", notes = "首页轮播图列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "place", value = "0为首页，1为惠积分", defaultValue = "0", dataType = "string")
    })
    public RestResponse bannerList(@RequestParam(defaultValue = "0") Integer place) {
        List<MallBannerEntity> bannerEntityList = bannerService.list(
                new QueryWrapper<MallBannerEntity>().eq("ENABLED", 1).ge("END_TIME", new Date())
                        .eq("PLACE", place)
                        .orderByDesc("SORT"));
        return RestResponse.success().put("data", bannerEntityList);
    }

    /**
     * 首页轮播图详情
     */
    @IgnoreAuth
    @GetMapping("/bannerDetail")
    @ApiOperation(value = "首页轮播详情", notes = "首页轮播为文本（mediaType=2）时，根据轮播ID获取详情")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "bannerId", value = "轮播ID", example = "1", required = true, dataType = "string")
    })
    public RestResponse bannerDetail(String bannerId) {
        MallBannerEntity bannerEntity = bannerService.getById(bannerId);
        return RestResponse.success().put("data", bannerEntity);
    }

    /**
     * 首页弹窗
     */
    @IgnoreAuth
    @GetMapping("/popupList")
    @ApiOperation(value = "首页弹窗列表", notes = "首页弹窗列表")
    public RestResponse popupList() {
        List<MallPopupEntity> popupEntities = popupService.list(
                new QueryWrapper<MallPopupEntity>().eq("STATUS", 1).orderByDesc("SORT"));
        return RestResponse.success().put("data", popupEntities);
    }


    /**
     * 首页栏目接口
     */
    @IgnoreAuth
    @GetMapping("/moduleCategoryList")
    @ApiOperation(value = "首页栏目接口", notes = "首页栏目接口")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "type", value = "类型，不传或者1为首页，其他为二级栏目页面全部展现",
                    example = "1", required = true, dataType = "int")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK", response = MallModuleCategoryEntity.class),
    })
    public RestResponse moduleCategoryList(@RequestParam(defaultValue = "1") Integer type) {
        List<MallModuleCategoryEntity> moduleCategoryEntityList = moduleCategoryService.list(
                new LambdaQueryWrapper<MallModuleCategoryEntity>()
//                        .eq(type == 1, MallModuleCategoryEntity::getHomepageShow, 1)
//                        .eq(type != 1, MallModuleCategoryEntity::getHomepageShow, 2)
                        .eq(MallModuleCategoryEntity::getShowLocation, type)
                        .orderByAsc(MallModuleCategoryEntity::getSort));
        final MallGoodsEntity[] mallGoodsEntity = new MallGoodsEntity[1];
        for (MallModuleCategoryEntity item : moduleCategoryEntityList) {
            // 下架不展示，所以不往下查数据
            if (item.getStatus() == 2) {
                continue;
            }
            item.setModuleEntities(moduleService.list(
                    new LambdaQueryWrapper<MallModuleEntity>()
//                            .eq(type == 1, MallModuleEntity::getHomepageShow, 1)
                            .eq(MallModuleEntity::getCategoryId, item.getId())
                            .eq(MallModuleEntity::getStatus, 1)
                            .orderByDesc(MallModuleEntity::getSort)));
        }
        return RestResponse.success().put("data", moduleCategoryEntityList);
    }

    /**
     * 根据分类id获取模块数据
     */
    @IgnoreAuth
    @GetMapping("/moduleByCategoryId")
    @ApiOperation(value = "根据分类id获取模块数据", notes = "根据分类id获取模块数据")
    @ApiImplicitParams({
    })
    public RestResponse moduleByCategoryId(@RequestParam(defaultValue = "") String id) {
        if (StringUtils.isBlank(id)) {
            return RestResponse.error("分类id不能为空");
        }
        List<MallModuleEntity> moduleEntities = moduleService.list(
                new LambdaQueryWrapper<MallModuleEntity>()
                        .eq(MallModuleEntity::getCategoryId, id).eq(MallModuleEntity::getStatus, 1)
                        .orderByDesc(MallModuleEntity::getSort));
        return RestResponse.success().put("data", moduleEntities);
    }

    /**
     * 首页频道列表
     */
    @IgnoreAuth
    @GetMapping("/channelList")
    @ApiOperation(value = "首页频道列表", notes = "首页频道列表")
    public RestResponse channelList() {
        List<MallChannelEntity> bannerEntityList = channelService.list(
                new QueryWrapper<MallChannelEntity>().eq("STATUS", 1).orderByDesc("SORT"));
        return RestResponse.success().put("data", bannerEntityList);
    }

    /**
     * 商城公告列表
     */
    @IgnoreAuth
    @GetMapping("/bulletinList")
    @ApiOperation(value = "商城公告列表", notes = "商城公告列表")
    public RestResponse bulletinList() {
        List<MallBulletinEntity> bulletinEntityList = bulletinService.list(
                new QueryWrapper<MallBulletinEntity>().eq("ENABLED", 1).orderByDesc("SORT"));
        return RestResponse.success().put("data", bulletinEntityList);
    }

    /**
     * 商城公告列表
     */
    @IgnoreAuth
    @GetMapping("/bulletinDetails")
    @ApiOperation(value = "商城公告详情", notes = "商城公告详情")
    public RestResponse bulletinDetails(String id) {
        MallBulletinEntity bulletin = bulletinService.getById(id);
        return RestResponse.success().put("data", bulletin);
    }

    /**
     * 个人中心统计
     */
    @GetMapping("userCount")
    @ApiOperation(value = "个人中心统计", notes = "个人中心统计数据")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "用户token", dataType = "string")
    })
    public RestResponse userCount(@LoginUser MallUserEntity user) {
        // 统计个人中心订单数据
        Map<String, Object> params = new HashMap<>(2);
        params.put("userId", user.getId());
        return RestResponse.success().put("countMap", orderService.queryUserCountMap(params));
    }

    /**
     * 获取是否开启余额支付功能
     * 1: 开启（默认）
     * 2：禁用
     */
    @IgnoreAuth
    @GetMapping("getRechargeStatus")
    @ApiOperation(value = "获取是否开启余额支付功能", notes = "获取是否开启余额支付功能")
    public RestResponse getRechargeStatus() {
        return RestResponse.success().put("rechargeStatus", sysConfigService.getValue(Constant.RECHARGE_STATUS, "2"));
    }

    /**
     * 发送短信
     */
    @IgnoreAuth
    @PostMapping("smsCode")
    @ApiOperation(value = "发送短信", notes = "发送短信验证码")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "用户token", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "body", name = "jsonParam", value = "JSON格式参数", examples = @Example({
                    @ExampleProperty(mediaType = "phone", value = "xx"),
                    @ExampleProperty(mediaType = "uuid", value = "xx"),
                    @ExampleProperty(mediaType = "code", value = "xx"),
                    @ExampleProperty(mediaType = "configId", value = "xx")
            }), required = true, dataType = "string")
    })
    public RestResponse smsCode(@RequestBody Map<String, String> params) {
        sysSmsLogService.build(params.get("phone"))
                .captchaValidate(params.get("uuid"), params.get("code"))
                .autoSend(params.get("configId"), params);
        return RestResponse.success("短信发送成功");
    }

    /**
     * 绑定手机
     */
    @PostMapping("bindMobile")
    @ApiOperation(value = "绑定手机", notes = "校验验证码绑定手机")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "用户token", required = true, dataType = "string"),

    })
    public RestResponse bindMobile(@RequestBody Map<String, String> map) {
        String mobile = map.get("mobile");
        if (StringUtils.isBlank(mobile)) {
            mobile = map.get("phone");
        }
        SmsUtil.codeValidate(jedisUtil, mobile, map.get("code"));
        userService.lambdaUpdate().set(MallUserEntity::getMobile, mobile).eq(MallUserEntity::getId, getUserId()).update();
        return RestResponse.success("手机绑定成功");
    }

    /**
     * 根据手机号修改密码
     */
    @IgnoreAuth
    @PostMapping("modifyPw")
    @ApiOperation(value = "修改密码", notes = "校验验证码修改密码，无需用户登录")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "jsonParam", value = "JSON格式参数", examples = @Example({
                    @ExampleProperty(mediaType = "mobile", value = "xx"),
                    @ExampleProperty(mediaType = "mobileCode", value = "1234"),
                    @ExampleProperty(mediaType = "password", value = "123456")
            }), required = true, dataType = "string")
    })
    public RestResponse modifyPw() {
        JSONObject jsonParams = getJsonRequest();

        String mobile = jsonParams.getString("mobile");
        String mobileCode = jsonParams.getString("mobileCode");
        String password = jsonParams.getString("password");

        String smsCode = jedisUtil.get(Constant.PRE_SMS + mobile);
        if (StringUtils.isNullOrEmpty(smsCode)) {
            return RestResponse.error("验证码已失效，请重新获取");
        }
        if (!mobileCode.equals(smsCode)) {
            return RestResponse.error("验证码错误");
        }
        MallUserEntity userVo = userService.queryByMobile(mobile);
        userVo.setMobile(mobile);
        userVo.setPassword(DigestUtils.sha256Hex(password));
        userService.update(userVo);

        //验证通过后删除redis中的验证码
        jedisUtil.del(Constant.PRE_SMS + mobile);
        return RestResponse.success("手机绑定成功");
    }


    /**
     * 微信小程序用户绑定手机号码
     */
    @GetMapping("bindMobileByMa")
    @ApiOperation(value = "微信小程序用户绑定手机号码", notes = "每次返回的code只能使用一次")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "code", value = "code", example = "1", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "referrer", value = "referrer", example = "1", dataType = "string")
    })
    public RestResponse bindMobileByMa(String code, @LoginUser MallUserEntity loginUser, String referrer) {
        AbstractAssert.isBlank(code, "绑定失败：code为空");

        try {
            String data = wxMaService.post("https://api.weixin.qq.com/wxa/business/getuserphonenumber"
                    , WxGsonBuilder.create().toJson(ImmutableMap.of("code", code)));
            log.info(data);
            JSONObject js = JSONObject.parseObject(data);
            WxMaPhoneNumberInfo wxMaPhoneNumberInfo = JSONObject.toJavaObject(js.getJSONObject("phone_info"), WxMaPhoneNumberInfo.class);
            userService.update(new LambdaUpdateWrapper<MallUserEntity>().set(MallUserEntity::getMobile, wxMaPhoneNumberInfo.getPurePhoneNumber())
                    .set(MallUserEntity::getReferrer, referrer)
                    .eq(MallUserEntity::getId, loginUser.getId()));

            return RestResponse.success();
        } catch (WxErrorException e) {
            log.error("微信小程序用户绑定手机号码修改失败：" + e.getMessage());
            return RestResponse.error("修改手机号码失败");
        }
    }

    /**
     * 微信小程序用户 修改用户信息
     */
    @GetMapping("updateUser")
    @ApiOperation(value = "微信小程序用户绑定手机号码", notes = "每次返回的code只能使用一次")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "code", value = "code", example = "1", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "code", value = "code", example = "1", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "code", value = "code", example = "1", required = true, dataType = "string")
    })
    public RestResponse updateUser(String nickName, String headImgUrl, @LoginUser MallUserEntity loginUser) {
        if (StringUtils.isBlank(headImgUrl) || StringUtils.isBlank(nickName)) {
            return RestResponse.error("缺少参数");
        }

        userService.update(new LambdaUpdateWrapper<MallUserEntity>()
                .set(!StringUtils.isBlank(headImgUrl), MallUserEntity::getHeadImgUrl, headImgUrl)
                .set(!StringUtils.isBlank(nickName), MallUserEntity::getNickname, nickName)
                .eq(MallUserEntity::getId, loginUser.getId()));

        return RestResponse.success();
    }


    /**
     * 发送短信
     */
    @IgnoreAuth
    @PostMapping("bindCustomerCode")
    @ApiOperation(value = "发送短信", notes = "发送短信验证码")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "jsonParam", value = "JSON格式参数", examples = @Example({
                    @ExampleProperty(mediaType = "mobile", value = "xx")
            }), required = true, dataType = "string")
    })
    public RestResponse bindCustomerCode() {

        JSONObject jsonParams = getJsonRequest();

        String mobile = jsonParams.getString("mobile");
        if (StringUtils.isBlank(mobile) || mobile.length() != 11) {
            return RestResponse.error("手机号码格式不对");
        }

        MallUserEntity mallUserEntity = userService.queryByMobile(mobile);
        if (mallUserEntity != null && mallUserEntity.getCustomerNo() != null) {
            return RestResponse.error("您已经绑定账号，请不要重复绑定");
        }

//        String configObject = sysConfigService.getValue(Constant.SMSTESTCODE);
        JSONObject configObject = sysConfigService.getConfigObject(Constant.SMSTESTCODE, JSONObject.class);
        Boolean isEnable = configObject.getBoolean("isEnable");
//        configObject.getJSONObject("isEnable").getBooleanValue();
        if (isEnable) {
            return RestResponse.success("短信发送成功");
        }

        String code = jedisUtil.get(Constant.PRE_SMS + mobile);
        // 一分钟之内不能重复发送短信
        String stint = jedisUtil.get(Constant.SMS_STINT + mobile);
        String smsCode;
        if (StringUtils.isNotBlank(stint)) {
            return RestResponse.success("短信已发送");
        } else {
            if (StringUtils.isNotBlank(code)) {
                smsCode = code;
            } else {
                //生成验证码
                smsCode = CharUtil.getRandomNum(6);
            }
        }
        //发送成功之后将验证码存入redis，有效期为5分钟
        jedisUtil.set(Constant.PRE_SMS + mobile, smsCode, 300);
        jedisUtil.set(Constant.SMS_STINT + mobile, smsCode, 60);
        jedisUtil.set(Constant.VERIFICATIONSNUMBER + mobile, "0", 300);
        SysSmsLogEntity smsLogVo = new SysSmsLogEntity();
        smsLogVo.setUserId("0");
        smsLogVo.setTemplateId(templateId);
        JSONObject js = new JSONObject();
        js.put("code", smsCode);
        smsLogVo.setCode(smsCode);
        smsLogVo.setContent(js.toString());
        smsLogVo.setMobile(mobile);
        smsLogVo.setStime(new Date());
//        sysSmsLogService.sendSms("0", smsLogVo, templateId);
        sysSmsLogService.sendSms("0", smsLogVo);
        return RestResponse.success("短信发送成功");
    }


    /**
     * 用户绑定银行客户号
     */
    @PostMapping("bindCustomer")
    @ApiOperation(value = "绑定客户号", notes = "绑定客户号")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "用户token", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "body", name = "jsonParam", value = "JSON格式参数", examples = @Example({
                    @ExampleProperty(mediaType = "phone", value = "xx"),
                    @ExampleProperty(mediaType = "code", value = "1234"),
                    @ExampleProperty(mediaType = "identNo", value = "身份证后四位"),
                    @ExampleProperty(mediaType = "custName", value = "姓名")
            }), required = true, dataType = "string")
    })
    public RestResponse bindCustomer(@LoginUser MallUserEntity loginUser) {
        JSONObject jsonParams = getJsonRequest();

        String mobile = jsonParams.getString("phone");
        String code = jsonParams.getString("code");
        String identNo = jsonParams.getString("identNo");
        String custName = jsonParams.getString("custName");
        String c = "dy2203";

        String oldCode = jedisUtil.get(Constant.PRE_SMS + mobile);
        if (StringUtils.isNullOrEmpty(oldCode) && !c.equals(code)) {
            return RestResponse.error("验证码已失效，请重新获取");
        }
        if (!code.equals(oldCode) && !c.equals(code)) {
            return RestResponse.error("验证码错误");
        }
        BkCustomerEntity bkCustomerEntity = bkCustomerService.getOne(new LambdaQueryWrapper<BkCustomerEntity>()
                .eq(BkCustomerEntity::getIdentNo, identNo)
                .eq(BkCustomerEntity::getLinkmanTel, mobile));
        if (bkCustomerEntity == null || StringUtils.isBlank(bkCustomerEntity.getCustomerNo()) || !custName.equals(bkCustomerEntity.getCustName())) {
            return RestResponse.error("手机号码尚未在银行登记，请到银行办理业务登记后再绑定用户");
        }
        MallUserEntity userEntity = new MallUserEntity();
        userEntity.setId(loginUser.getId());
        userEntity.setCustomerNo(bkCustomerEntity.getCustomerNo());
        userEntity.setBalance(null);
        userEntity.setSignUsedIntegral(null);
        userEntity.setSignAllIntegral(null);
        userService.update(userEntity);

        //验证通过后删除redis中的验证码
        jedisUtil.del(Constant.PRE_SMS + mobile);
        return RestResponse.success("绑定成功");
    }


    /**
     * 用户取消收藏活动
     */
    @PostMapping("/eventCancelCollection")
    @ApiOperation(value = "用户取消收藏活动", notes = "用户取消收藏活动")
    public RestResponse eventCancelCollection(@RequestParam(defaultValue = "") String categoryId, @RequestParam(defaultValue = "") String eventId, @LoginUser MallUserEntity userEntity) {
        if (StringUtils.isBlank(eventId)) {
            return RestResponse.error("活动id不能为空");
        }
        if (StringUtils.isBlank(categoryId)) {
            return RestResponse.error("卡种id不能为空");
        }
        int count = eventUserService.count(new QueryWrapper<EventUserEntity>().eq("category_id", categoryId).eq("event_id", eventId).eq("open_id", userEntity.getOpenId()));
        if (count <= 0) {
            return RestResponse.error("用户没有收藏此活动");
        }
        eventUserService.remove(new QueryWrapper<EventUserEntity>().eq("category_id", categoryId).eq("event_id", eventId).eq("open_id", userEntity.getOpenId()));
        return RestResponse.success();
    }

    /**
     * 用户收藏活动
     */
    @PostMapping("/eventCollection")
    @ApiOperation(value = "用户收藏活动", notes = "用户收藏活动")
    public RestResponse eventCollection(@RequestParam(defaultValue = "") String categoryId, @RequestParam(defaultValue = "") String eventId, @LoginUser MallUserEntity userEntity) {
        if (StringUtils.isBlank(eventId)) {
            return RestResponse.error("活动id不能为空");
        }
        if (StringUtils.isBlank(categoryId)) {
            return RestResponse.error("卡种id不能为空");
        }
        int count = eventUserService.count(new QueryWrapper<EventUserEntity>().eq("category_id", categoryId).eq("event_id", eventId).eq("open_id", userEntity.getOpenId()));
        if (count > 0) {
            return RestResponse.error("活动重复收藏");
        }
        EventUserEntity e = new EventUserEntity();
        e.setEventId(eventId);
        e.setCategoryId(categoryId);
        e.setOpenId(userEntity.getOpenId());
        eventUserService.save(e);
        return RestResponse.success();
    }

    /**
     * 用户收藏活动列表
     */
    @GetMapping("/myEventCollection")
    @ApiOperation(value = "用户收藏活动列表", notes = "用户收藏活动列表")
    public RestResponse myEventCollection(@LoginUser MallUserEntity userEntity) {

        List<EventUserEntity> event = eventUserService.list(new QueryWrapper<EventUserEntity>().eq("open_id", userEntity.getOpenId())
                .orderByDesc("ADD_TIME"));
        List<EventCalendarEntity> list = new ArrayList<>();

        for (EventUserEntity dto : event
        ) {
            EventCalendarEntity ece = eventCalendarService.getById(dto.getEventId());
            if (org.apache.commons.lang3.ObjectUtils.allNotNull(ece) && ece.getStatus() == 1) {
                EventCalendarCategoryEntity ecce = eventCalendarCategoryService.getById(dto.getCategoryId());
                ece.setCategoryId(dto.getCategoryId());
                ece.setCategoryTitle(ecce.getTitle());
                list.add(ece);
            }
        }
        return RestResponse.success().put("data", list);
    }

}
